/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Principal.java
 *
 * Created on 10/05/2011, 11:29:34
 */
package pt.c03ensaios.debolacha.visual;

import anima.component.IRequires;
import anima.context.exception.ContextException;
import anima.factory.IGlobalFactory;
import anima.factory.context.componentContext.ComponentContextFactory;
import anima.factory.exception.FactoryException;
import pt.c03ensaios.debolacha.app.Game;
import pt.c03ensaios.debolacha.impl.AnimalFile;
import pt.c03ensaios.debolacha.inter.IAnimalFile;
import pt.c03ensaios.linnaeus.AnimalsDatabase;
import pt.c03ensaios.linnaeus.IAnimalsDatabase;
import pt.c03ensaios.lobo.impl.AnimalCreatorGUI;
import pt.c03ensaios.lobo.inter.IAnimalCreatorGUI;
import pt.c03ensaios.naxxramas.INaxxramas;
import pt.c03ensaios.naxxramas.Naxxramas;
import pt.c03ensaios.tochinhas2.impl.IQuestions;
import pt.c03ensaios.tochinhas2.impl.Questions;


/**
 *
 * @author Douglas
 */
public class Principal extends javax.swing.JFrame {

	private static final long serialVersionUID = 1L;
	/** Creates new form Principal */
    public Principal() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(255, 255, 255));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 0, 0), 2, true));
        jPanel1.setLayout(null);

        jLabel1.setFont(new java.awt.Font("Comic Sans MS", 1, 30));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Bem-vindo ao DeBolacha");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(0, 0, 400, 74);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Escolha uma opcao abaixo:");
        jPanel1.add(jLabel2);
        jLabel2.setBounds(0, 92, 400, 30);

        jButton1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jButton1.setText("Jogar!!!");
        jButton1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0)));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1);
        jButton1.setBounds(10, 165, 170, 50);

        jButton2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jButton2.setText("Adicionar Animais");
        jButton2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0)));
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton2);
        jButton2.setBounds(220, 165, 170, 50);

        jLabel4.setBackground(new java.awt.Color(255, 255, 255));
        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pt/c03ensaios/debolacha/image/Logo Rhino.png"))); // NOI18N
        jPanel1.add(jLabel4);
        jLabel4.setBounds(50, 0, 310, 300);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        new Game();
    }//GEN-LAST:event_jButton1ActionPerformed

    
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    	IGlobalFactory factory;
		try {
			factory = ComponentContextFactory.createGlobalFactory();
		

			factory.registerPrototype(AnimalCreatorGUI.class);
			IAnimalCreatorGUI creator = factory.createInstance(
				"<http://purl.org/dcc/pt.c03ensaios.lobo.impl.AnimalCreatorGUI>");
			
			factory.registerPrototype(AnimalFile.class);
			IAnimalFile file = factory.createInstance(
				"<http://purl.org/dcc/pt.c03ensaios.debolacha.impl.AnimalFile>");
			
			factory.registerPrototype(Questions.class);
			IQuestions question = factory.createInstance(
				"<http://purl.org/dcc/pt.c03ensaios.tochinhas2.impl.Questions>");
			
			IRequires<IAnimalsDatabase> questionReceptacle = question.queryReceptacle(
					"<http://purl.org/dcc/pt.c03ensaios.linnaeus.IAnimalsDatabase>");
			
			factory.registerPrototype(AnimalsDatabase.class);
			IAnimalsDatabase animals = factory.createInstance(
					"<http://purl.org/dcc/pt.c03ensaios.linnaeus.AnimalsDatabase>");
			
			IRequires<IQuestions> animalsReceptacle = animals.queryReceptacle(
					"<http://purl.org/dcc/pt.c03ensaios.tochinhas2.impl.IQuestions>");

			factory.registerPrototype(Naxxramas.class);
			INaxxramas naxx = factory.createInstance(
					"<http://purl.org/dcc/pt.c03ensaios.naxxramas.Naxxramas>");
			
			questionReceptacle.connect(animals);
			animalsReceptacle.connect(question);
			((AnimalFile) file).connect(animals);
			
			
			creator.connect(file);
			creator.connect(question);
			
			creator.initialize();
			creator.setTestMode(false);
			creator.connect(naxx);
			naxx.setVisible(true);
		} catch (ContextException e) {
			e.printStackTrace();
		} catch (FactoryException e) {
			e.printStackTrace();
		}
	}//GEN-LAST:event_jButton2ActionPerformed

    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Principal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
